<?php
/**
 * Created by PhpStorm
 * User: honglin
 * Date: 2022/8/9
 * Time: 下午4:27
 */

namespace App\Controller\Ocean;

use App\Middleware\AuthTokenMiddleware;
use App\Service\Ocean\OceanFishService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Middleware;
use Yj\Apidog\Annotation\ApiController;
use Yj\Apidog\Annotation\FormData;
use Yj\Apidog\Annotation\PostApi;

/**
 * @Middleware(AuthTokenMiddleware::class)
 * @ApiController(prefix="ocean/fish")
 *
 */
class OceanFishController extends BaseController
{

    /**
     * @Inject()
     * @var OceanFishService
     */
    protected $oceanFishService;

    /**
     * 兑换
     * @PostApi(path="exchange")
     * @FormData(key="fish_id")
     */
    public function exchange()
    {
        $fish_id = $this->getParams()->get('fish_id');
        $userId = $this->getUid();
        $this->oceanFishService->exchange($fish_id, $userId);
        _SUCCESS();
    }

    /**
     * @PostApi(path="lists")
     */
    public function lists()
    {
        $params = $this->getParams();
     
        $data = $this->oceanFishService->page(false)->lists($params);
        _SUCCESS($data);
    }

    /**
     * 出售
     * @PostApi(path="sell")
     * @FormData(key="user_fish_id")
     */
    public function sell()
    {
        $user_fish_id = $this->getParams()->get('user_fish_id');
        $userId = $this->getUid();
        $this->oceanFishService->sell($user_fish_id, $userId);
        _SUCCESS();
    }
}